package blog132;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class Add extends HttpServlet {
    ServBean sql = new ServBean();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        sql.addMessage(req.getParameter("message"));
        if (sql.getErrorText()=="") {
            sql.disconnect();
            resp.sendRedirect("/web/index.jsp");
        }else {
            PrintWriter out;
            resp.setContentType("text/html;charset=UTF-8");
            out = resp.getWriter();
            out.println(sql.getErrorText());
            out.println("<br><A HREF='/web/add.jsp'>Добавить</A>");
            out.println("<br><A HREF='/web/index.jsp'>Главная</A>");
        }
    }
}
